<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>
<html>
    <head>
        <title>比呀比-首页</title>
        <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css">
        <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/icon.css">
        <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/js/jquery.min.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/js/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/js/form.validator.rules.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/js/easyui-lang-zh_CN.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/js/jquery.edatagrid.js"></script>

        <script type="text/javascript">
            function loading(){
                if(${admin==null}){
                    $("#loginDialog").dialog({
                        title:"登录",
                        iconCls:'icon-save',
                        closable:false,
                        width:600,
                        modal:true,
                        height:400,
                        href:"${pageContext.request.contextPath}/back/admin/login.jsp",
                        buttons:[{
                            text:'登录',
                            iconCls:'icon-ok',
                            handler:login,
                        }]
                    });
                }else{
                    $("#lougouBtn").css("display","block");
                    $("#welcome").html ($("#welcome").html()+"<img style='width:60px;height:60px;display: inline-block;border-radius: 50%;' src='${pageContext.request.contextPath}/back/img/admin.png'/><span style='font-size:18px;position: relative;top: -10px;margin-left:10px;'>${admin.realname}</span>");
                    $.get("${pageContext.request.contextPath}/back/menu/getMenu",function (data) {

                        $.each(data,function (index,menu) {
                            var content = "<div style='text-align: center;'>";
                            $.each(menu.children,function(i,child){
                                var json = JSON.stringify(child);
                                content+="<a class='easyui-linkbutton' onclick='tab("+ json +")' style='width:90%;height:40px;margin-top:10px;border:1px solid #63AAE3;' data-options=\"iconCls:'"+child.iconCls +"',plain:true,\">"+child.title+"</a>";
                            });
                            content+="</div>"
                            if(index==0)menu.selected=true;
                            $("#aa").accordion("add",$.extend({
                                "content":content,
                                "selected":false
                            },menu));
                        })
                    });


                }
            }
            $(function(){
                loading();
            });
            function tab(child){
                if(!$("#tabs").tabs("exists",child.title)){
                    $("#tabs").tabs("add",{
                        title:child.title,
                        iconCls:child.iconCls,
                        closable:true,
                        href:'${pageContext.request.contextPath}/'+child.href,
                    });
                }else{
                    $("#tabs").tabs("select",child.title);
                }

                /*if(child.title=="订单列表"){
                    $("#js").append($("<div id='jsdiv'><script src='${pageContext.request.contextPath}/easyui/js/datagrid-detailview.js'>"));
                }else{
                    $("#js").empty();
                }*/
            }
            function login() {
                $('#loginForm').form({
                    url:'${pageContext.request.contextPath}/back/admin/login',
                    onSubmit: function(){
                        return $("#loginForm").form("validate");
                    },
                    success:function(result){
                        result = eval("("+ result +")");
                        if(result.status){

                            $('#loginDialog').dialog("close");

                            $("#lougouBtn").css("display","block");
                            $.messager.show({
                                title:'提示信息',
                                msg:"登录成功！",
                                timeout:5000,
                                showType:'slide'
                            });
                            $.get("${pageContext.request.contextPath}/back/menu/getMenu",function (data) {
                                $.each(data,function (index,menu) {
                                    var content = "<div style='text-align: center;'>";
                                    $.each(menu.children,function(i,child){
                                        var json = JSON.stringify(child);
                                        content+="<a class='easyui-linkbutton' onclick='tab("+ json +")' style='width:90%;height:40px;margin-top:10px;border:1px solid #63AAE3;' data-options=\"iconCls:'"+child.iconCls +"',plain:true,\">"+child.title+"</a>";
                                    });
                                    content+="</div>"
                                    if(index==0)menu.selected=true;
                                    $("#aa").accordion("add",$.extend({
                                        "content":content,
                                        "selected":false
                                    },menu));
                                })
                            });

                            $("#welcome").html ($("#welcome").html()+"<img style='width:60px;height:60px;display: inline-block;border-radius: 50%;' src='${pageContext.request.contextPath}/back/img/admin.png'/><span style='font-size:18px;position: relative;top: -10px;margin-left:10px;'>"+result.message+"</span>");
                        }else{
                            $.messager.show({
                                title:'提示信息',
                                msg:result.message,
                                timeout:5000,
                                showType:'slide'
                            });
                            $('#loginForm').form("clear");
                        }
                    }
                });
                $('#loginForm').submit();
            }
            function logout() {
                $.ajax({
                    type:"GET",
                    url:"${pageContext.request.contextPath}/back/admin/logout",
                    data:"",
                    success:function (d) {
                        $.messager.show({
                            title:'提示信息',
                            msg:d.message,
                            timeout:5000,
                            showType:'slide'
                        });
                        if(d.status){
                            window.location.reload();
                        }
                    }
                });
            }
        </script>
    </head>
    <body>
    <div id="js"></div>
        <div class="easyui-layout" data-options="fit:true">
            <div data-options="region:'north',split:false" style="height:100px;background-color: #E8F1FF;">
                <h1 style="text-align: center">机器人后台管理系统</h1>
                <div id="welcome" style="position: absolute;right: 220px;top: 30px;"><a id="lougouBtn" style="display:none;position: absolute;right: -150px;top: 30px;" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true," onclick="logout()">退出</a></div>
            </div>
            <div data-options="region:'south',split:false" style="height:80px;">
                <div style="text-align: center;line-height: 70px;background-color: #E8F1FF;">
                    比呀比科技有限公司@版权所有
                </div>
            </div>
            <div data-options="region:'west',title:'菜单',split:false" style="width:200px;">

                <div id="aa" class="easyui-accordion" data-options="fit:true">
                </div>

            </div>
            <div data-options="region:'center'">
                <div id="tabs" class="easyui-tabs" data-options="fit:true,">
                    <div data-options="title:'首页',closable:false,iconCls:'icon-reload'">
                        <img src="${pageContext.request.contextPath}/back/img/5fdc1601f20b924bec0627bf5db0f9f4.jpg" width="100%"  alt="">
                    </div>

                </div>
            </div>
        </div>
        <div id="loginDialog"></div>
    </body>
</html>
